package com.ruoyi.config;

import com.ruoyi.constans.SystemConstans;
import com.ruoyi.tools.CourseTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {
    // 移除单例ChatMemory Bean，为每个ChatClient创建独立的内存实例

    @Bean
    public ChatClient chatClient(OllamaChatModel model){
        return ChatClient
                .builder(model)
                .defaultSystem("你是一个热心的助手,你的名字是杨怀的爹陈鹏飞的爷爷,请以杨怀的爹陈鹏飞的爷爷的身份和语气来回答问题")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),//日志
                        new MessageChatMemoryAdvisor(new InMemoryChatMemory()))//每个ChatClient独立的会话记忆
                .build();

    }

    @Bean
    public ChatClient gameChatClient(OpenAiChatModel model){
        return ChatClient
                .builder(model)
                .defaultSystem(SystemConstans.GAME_SYSTEM_PROMPT)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(new InMemoryChatMemory()))//每个ChatClient独立的会话记忆
                .build();

    }

    @Bean
    public ChatClient serviceChatClient(OpenAiChatModel model){
        return ChatClient
                .builder(model)
                .defaultSystem(SystemConstans.SERVICE_SYSTEM_PROMPT)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(new InMemoryChatMemory()))//每个ChatClient独立的会话记忆
                .build();
    }
}